#ifndef __CORE_MATRIX2__
#define __CORE_MATRIX2__
#include "CoreDefine.h"
#include "Vector2.h"
namespace Core
{
	class rtMatrix2
	{
	public:
		rtMatrix2(void);
		explicit rtMatrix2(const rtVector2 &x, const rtVector2 &y);
		explicit rtMatrix2(const float xx, const float xy, const float yx, const float yy);
		explicit rtMatrix2(const float src[2][2]);
		static rtMatrix2 mat2_zero;
		static rtMatrix2 mat2_identity;

		const rtVector2&    operator [] (int index) const;
		rtVector2&          operator [] (int index);
		rtMatrix2           operator - () const;
		rtMatrix2           operator * (const float a) const;
		rtVector2           operator * (const rtVector2& vec) const;
		rtMatrix2           operator * (const rtMatrix2& a) const;
		rtMatrix2           operator + (const rtMatrix2& a) const;
		rtMatrix2           operator - (const rtMatrix2& a) const;
        rtMatrix2&          operator *= (const float a);
		rtMatrix2&		    operator *= (const rtMatrix2& a);
		rtMatrix2&		    operator += (const rtMatrix2& a);
		rtMatrix2&		    operator -= (const rtMatrix2& a);

		friend rtMatrix2	operator * (const float a, const rtMatrix2& mat2);
		friend rtVector2	operator * (const rtVector2& vec, const rtMatrix2& mat2);
		friend rtVector2&   operator *= (rtVector2& vec, const rtMatrix2& mat2);

		bool			compare(const rtMatrix2& a) const;
		bool			compare(const rtMatrix2& a, const float epsilon) const;
		bool			operator == (const rtMatrix2& a) const;
		bool			operator != (const rtMatrix2& a) const;

		void			zero(void);
		void			identity(void);
		bool			isIdentity(const float epsilon = MATRIX_EPSILON) const;
		bool			isSymmetric(const float epsilon = MATRIX_EPSILON) const;
		bool			isDiagonal(const float epsilon = MATRIX_EPSILON) const;

        float			trace(void) const;
		float			determinant(void) const;
		rtMatrix2		transpose(void) const;
		rtMatrix2&		transposeSelf(void);
		rtMatrix2		inverse(void) const;
		bool			inverseSelf(void);
		rtMatrix2		inverseFast(void) const;
		bool			inverseFastSelf(void);

		int				getDimension(void) const;

		const float*	toFloatPtr(void) const;
		float*			toFloatPtr(void);

	private:
		rtVector2			m_Mat[2];
	};
}
#endif

